//
//  where.swift
//  TestSwift
//
//  Created by 小星星吃KFC on 2021/5/29.
//

import Foundation


func TestWhere(){
    
    
    let name = [20,8,59,60,70,80,98]
    print("不及格\(name)")
    //name.forEach { val in
    //    print("不及格\(val)")
    //
    //}
    //
    
    //使用forEach正向遍历
    name.forEach { (word) in
        print(word)
    }
    name.filter({  (val) in
        return val>=60
    }).forEach { (val) in
        print(val)
    }
    
    let flatMapArr = name.filter({  (val) in
        return val>=60
    }).map { (val) in
        return "map:\(val)"
    }
    print("flatMapArr=\(flatMapArr)")
    
    
    name.dropFirst().forEach { (val) in
        print("除去第一个元素以外的部分元素:\(val)")
    }
    
    name.dropFirst(4).forEach { (val) in
        print("除去第指定个元素以外的部分元素:\(val)")
    }
    
    
    do {
        
        let flatMapArr = name.filter({  (val) in
            return val>=60
        }).flatMap { (val) in
            return "flatMap:\(val)"
        }
        print("分割成每个字符=\(flatMapArr)")
        
    }
    do {
        
        let flatMapArr = name.filter({  (val) in
            return val>=60
        }).flatMap { (val) in
            return ["flatMap:\(val)"]
        }
        print("flatMap=\(flatMapArr)")
        
    }
    //使用forEach的反向遍历
    name.reversed().forEach { (word) in
        print(word)
    }
    
    
    
    name.forEach { val  in
        switch val{
        case let x where x>=60:
            print("\(val)及格")
        default:
            print("\(val)不及格")
        }
    }
    
    name.forEach {
        switch $0{
        case let x where x>=60:
            print("\($0)及格")
        default:
            print("\($0)不及格")
        }
    }
    
    
    
  
    
}

